home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacWT 0.9 / wt Mac Source / Music.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-10  |  2.0 KB  |  124 lines  |  [TEXT/CWIE]

  1. /*
  2. ** File:        Music.c
  3. **                Easy to use wrapper for the MADF music file playing library
  4. **
  5. ** Written by:    Bill Hayden
  6. **                Nikol Software
  7. **
  8. ** Copyright © 1995 Nikol Software
  9. ** All rights reserved.
  10. */
  11.  
  12.  
  13.  
  14. #include "Music.h"
  15. #include "MAD.h"
  16. #include "RDriver.h"
  17. #include "Sound.h"
  18.  
  19. Boolean    Playing = FALSE;
  20.  
  21. OSErr    LoadMusicDriver(void)
  22. {
  23.     Boolean        Stereo, StereoMixing, NewSoundManager = TRUE, hasASC;
  24.     long        gestaltAnswer;
  25.     short        myBit;
  26.     NumVersion    nVers;
  27.  
  28.  
  29.  
  30.     // HARDWARE IDENTIFICATION
  31.  
  32.     /****************/
  33.     /** ASC CHIP ? **/
  34.     /****************/
  35.  
  36.     Gestalt( gestaltHardwareAttr, &gestaltAnswer);
  37.     myBit = gestaltHasASC;
  38.     if( BitTst( &gestaltAnswer, 31-myBit) == false)
  39.         hasASC = false;
  40.     else
  41.         hasASC = true;
  42.  
  43.     /**************/
  44.     /** STEREO ? **/
  45.     /**************/
  46.  
  47.     Gestalt( gestaltSoundAttr, &gestaltAnswer);
  48.     myBit = gestaltStereoCapability;
  49.     Stereo = BitTst( &gestaltAnswer, 31-myBit);
  50.  
  51.     /*********************/
  52.     /** STEREO MIXING ? **/
  53.     /*********************/
  54.  
  55.     myBit = gestaltStereoMixing;
  56.     StereoMixing = BitTst( &gestaltAnswer, 31-myBit);
  57.  
  58.     /****************************/
  59.     /** SOUND MANAGER >= 3.0 ? **/
  60.     /****************************/
  61.  
  62.     nVers = SndSoundManagerVersion();
  63.     if( nVers.majorRev >= 3 )
  64.         NewSoundManager = true;
  65.     else
  66.         NewSoundManager = false;
  67.  
  68.     // choose the best driver for the current hardware
  69.  
  70.     if( Stereo && StereoMixing )
  71.         {        
  72.         if( NewSoundManager == true)
  73.             return RInitMusic( SMStereo, 4);
  74.         else if ( hasASC )
  75.             return RInitMusic( ASCStereo, 4);
  76.         else
  77.             return RInitMusic( SMDSP, 4);
  78.         }
  79.     else
  80.         {        
  81.         if( NewSoundManager )
  82.             {
  83.             return RInitMusic( SMMono, 4);
  84.             }
  85.         else if( hasASC )
  86.             {
  87.             return RInitMusic( ASCMono, 4);
  88.             }
  89.         }
  90.         
  91.     return -1;
  92.  
  93. }
  94.  
  95.  
  96.  
  97. void    PlayMusic(short    ResNum)
  98. {
  99.     RLoadMusicRsrc( 'MADF', ResNum );
  100.     
  101.     RPlayMusic();
  102.     Reading = true;
  103.     Playing = true;
  104. }
  105.  
  106.  
  107.  
  108. void StopMusic(void)
  109. {
  110.     if (Playing)
  111.         {
  112.         RStopMusic();            // Stop music
  113.         CleanDriver();
  114.         RClearMusic();            // Dispose the current music
  115.         Playing = false;
  116.         }
  117. }
  118.  
  119.  
  120.  
  121. OSErr    DisposeMusicDriver(void)
  122. {
  123.     RQuitMusic();
  124. }